package com.zhaoc.dao;


import com.zhaoc.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * <p>title:com.zhaoc.dao</p>
 * date:2018/8/4 0004
 * time:18:52
 * author:赵成
 * user:13566
 */
public interface CustomerRepository extends JpaRepository<Customer,Integer>{

    //查询所有未关联的客户信息
    List<Customer> findByFixedAreaIdIsNull();

    List<Customer> findByFixedAreaId(String fixedAreaId);

    @Query("update Customer set fixedAreaId = ?2 where id = ?1")
    @Modifying
    public void updateFixedAreaId(Integer id,String fixedAreaId);

    @Query("update Customer set fixedAreaId = null where fixedAreaId = ?1")
    @Modifying
    void claerFixedAreaId(String fixedAreaId);

    Customer findBytelephone(String telephone);

    @Query("update Customer set type = 1 where telephone = ?1")
    @Modifying
    void updateTypeByTelephone(String telephone);

    Customer findByTelephoneAndPassword(String telephone, String password);

    @Query("select fixedAreaId from Customer where address = ?1")
    String findFixedAreaIdByAddress(String address);
}
